<section class="content-header" >
    <h1>
        线路管理
        <small>线路列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="{:U('/Admin/index')}"><i class="fa fa-home"></i>首页</a></li>
        <li class="active">线路管理</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="box-title"><label >线路列表</label></div>
                    <div class="pull-right">
                        <button class="btn btn-block btn-primary btn-sm "onclick="addRoads()"><i class="fa fa-plus"></i>&nbsp;&nbsp;&nbsp;添加线路</button>
                    </div>
                </div><!-- /.box-header -->
                <div class="box-body">
                    <table id="table" class="table table-bordered table-striped" width="100%">
                        <thead>
                            <tr>
                                <th>编号</th>
                                <th>装料站</th>
                                <th>抵达地址</th>
                                <th>线路</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                    </table>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</section><!-- /.content -->
<!-- DATA TABES SCRIPT -->
<!-- page script -->
<script type="text/javascript">
    var taskTable = null;
    $(function () {
        taskTable =  $('#table').dataTable({
            "autoWidth": true,
//            "order": [4,'desc'],
            "processing": true, //载入数据的时候是否显示“载入中”
            'ordering': false, //排序操作在服务端进行，所以可以关了。
            'serverSide': true,
            "searching": false,
            "ajax": {
                "url": "{:U('Task/roads')}",
                "type": "POST"
            },
            "columns": [
                {"data": "number"},
                {"data": "task_from"},
                {"data": "task_end"},
                {"data": "id"},
                {"data": "status"},
                {"data": "id"}
            ],
            "columnDefs": [
                {
                    "targets": 1,
                    "render": function (data, type, row) {
                        return data+"<br/>电话:"+row.site_mobile;
                    }
                },
                {
                    "targets": 2,
                    "render": function (data, type, row) {
                        return "联系人:"+row.linkman+",电话:"+row.mobile+"<br/>"+data;
                    }
                },
                {
                    "targets": 3,
                    "render": function (data, type, row) {
                        return "<a href='javascript:getRoads(" + data + "," + row.task_from_longitude + "," + row.task_from_latitude + ","
                                + row.task_end_longitude + "," + row.task_end_latitude + ")'>线路规划</a>";
                    }
                },
                {
                    "targets": 4,
                    "render": function (data, type, row) {
                        return data==0?'启用':"<span style='color: red;'>停用</span>";
                    }
                },
                {
                    "targets": 5,
                    "render": function (data, type, row) {
                        var html ="";
                            html+='<a href="javascript:uptateItem(' +data + ')"><i class="fa fa-edit"></i>&nbsp;编辑</a>';
                        return html;
                    }
                }
            ],
            "language": lang
        });

    });

    function uptateItem(id) {
        var url = "{:U('task/addRoads')}";
        url += url.indexOf('?') != -1 ? '&id=' + id : '?id=' + id;
        $.dialog(url, '修改任务信息', null,42);
    }


    function addRoads() {
        $.dialog("{:U('task/addRoads')}", '添加线路',null,42);
    }

    function getRoads(id,slong,slat,elong,elat){
        var url = '{:U("Task/getRoads")}?id='+id+'&slng='+slong+"&slat="+slat+'&elng='+elong+"&elat="+elat;
        $.dialog(url, '线路规划', null,46,'getRoads');
    }

    function sendToCar(id){
        var url = "{:U('task/sendToCar')}";
        url += url.indexOf('?') != -1 ? '&id=' + id : '?id=' + id;
        $.dialog(url, '发布任务', null,40);
    }
</script>